source("perceptron.R")

maxit <- 100
learn.rate <- 0.1

# load data from the file 'breast-cancer.dat.shuf'
dat <- read.table("breast-cancer.dat.shuf") 
in.dim <- dim(dat)[2] - 1

x <- as.matrix(dat[,2:in.dim+1])
y <- as.matrix((dat[,1] == dat[1,1]) * 1)

# split the dataset
splitdat <- split.data(x, y, 10)

# train a perceptron
model <- perceptron(splitdat$x.train, splitdat$y.train, 
					maxit = maxit, learn.rate = learn.rate)

# report results
plot(1:maxit, model$errors, type="l", xlab="iter", ylab="error")

#cat("train accuracy: ", compute.accuracy(model, splitdat$x.train, splitdat$y.train), "\n")
cat("test accuracy: ", compute.accuracy(model, splitdat$x.test, splitdat$y.test), "\n")

